package org.zwt.server;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.zwt.server.ServerThread;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class HttpServer {
    private ServerSocket server;
    private Integer port;

    public HttpServer(Integer port) {
        this.port = port;
//        初始化ServerSocket
        try {
            this.server = new ServerSocket(port);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    public void start() throws IOException {
//        启动服务器
        System.out.println("正在监听" + this.port + "端口.....");

        while (true) {
            Socket socket = this.server.accept();
            new Thread(new ServerThread(socket)).start();

        }
    }
}
